/**
 * com.cnhis.his.customer.service.Bef1Service.java
 */
package com.mbmed.doctor.medadvice.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.mbmed.doctor.commons.mapper.ModelVo;
import com.mbmed.doctor.medadvice.bo.Bef1Bo;
import com.mbmed.doctor.medadvice.mapper.Bbx1;
import com.mbmed.doctor.medadvice.mapper.Bef1;

/**
 * @file  Bef1Service.java
 * @author 刘武
 * @version 0.1
 * @todo	Bef1服务操作接口
 * Copyright(C), 2013-2014
 *		 Shenzhen Coordinates Software Development Co., Ltd.
 * History
 *   	1. Date: 2014-11-11 02:23:26
 *      	Author: 刘武
 *      	Modification: this file was created
 *   	2. ...
 */
@Path("/bef1")
@Component
public class Bef1Service {
	
	private static Logger logger = Logger.getLogger(Bef1.class);
	
	@Autowired
	private Bef1Bo bef1Bo;
	
	@Context
	Request request;

	
	/**
	 * 查找所有数据库记录
     * @return type : List 返回查询操作所有符合条件的记录的VO对象集合，操作失败返回null
     */
	@GET
	@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
    public List<Bef1> getAll() throws Exception{
        List<Bef1> list = new ArrayList<Bef1>();
        return bef1Bo.getAll();        
    }
	
    /**
     * 查找符合条件的所有数据库记录
     * @param id 与数据库中主键对应的值
     * @return type :  返回查询操作所有符合条件的记录的VO对象，操作失败返回null
     * @throws Exception
     */
	@GET
	@Path("{id}")
	@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
    public Bef1 getBef1(@PathParam("id") String id) throws Exception{
    	Bef1 bef1 = null;
    	return bef1Bo.get(id);        
    }
    /**
     * 向数据库中插入一条记录
     * @param vo 与数据库中记录对应的值对象
     * @return type : 返回插入操作是否成功
     * @throws Exception
     */
	
	
	
	/**
     * 治疗方案查询
     * @param id 与数据库中主键对应的值
     * @return type :  药品：门诊按规格下医嘱，操作失败返回null
     * @throws Exception
     */
	@GET
	@Path("/getadvicetreatmentplan")
	@Produces({MediaType.APPLICATION_JSON})
    public ModelVo  getAdviceTreatmentPlan(
    		@QueryParam("bbx01a") java.lang.String bbx01a,
    		@QueryParam("acf01") java.lang.String acf01,
    		@QueryParam("lcheck") java.lang.String lcheck,
    		@QueryParam("bck01") java.lang.String bck01,
    		@QueryParam("bckyf") java.lang.String bckyf
    		) throws Exception{
		ModelVo modelVo = new ModelVo();
		int bbx01ab = Integer.parseInt(bbx01a);
		int acf01a = Integer.parseInt(acf01);
		int lcheckl = Integer.parseInt(lcheck);
		int bck01b = Integer.parseInt(bck01);
		int bckyfb = Integer.parseInt(bckyf);
		
		List<Bbx1> bbx1list = new ArrayList<Bbx1>();
		Map<String,Object> paramap = new HashMap<String,Object>();
		paramap.put("bbx01a", bbx01ab);
		paramap.put("acf01", acf01a);
		paramap.put("lcheck", lcheckl);
		paramap.put("bck01", bck01b);
		paramap.put("bckyf", bckyfb);
		
		bbx1list = bef1Bo.getAdviceTreatmentPlan(paramap);
		
		modelVo.setList(bbx1list);
		
    	return modelVo;
	}
	
	/**
     * 中药方剂信息查询
     * @param id 与数据库中主键对应的值
     * @return type :  药品：门诊按规格下医嘱，操作失败返回null
     * @throws Exception
     */
	@GET
	@Path("/getadvicechineseplan")
	@Produces({MediaType.APPLICATION_JSON})
    public ModelVo  getAdviceChinesePlan(
    		@QueryParam("BBX01A") java.lang.String bbx01a
    		) throws Exception{
		ModelVo modelVo = new ModelVo();
		int bbx01ab = Integer.parseInt(bbx01a);
		
		List<Bbx1> bbx1list = new ArrayList<Bbx1>();
		Map<String,Object> paramap = new HashMap<String,Object>();
		paramap.put("bbx01a", bbx01ab);
		
		bbx1list = bef1Bo.getAdviceChinesePlan(paramap);
		
		modelVo.setList(bbx1list);
		
    	return modelVo;
	}
	
	
	@POST
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public Bef1 saveBef1(
			@FormParam("bef01") java.lang.Integer bef01,
			@FormParam("bbx01a") java.lang.Integer bbx01a,
			@FormParam("rownr") java.lang.Integer rownr,
			@FormParam("bbx01b") java.lang.Integer bbx01b,
			@FormParam("bef05") java.lang.Integer bef05,
			@FormParam("bbx01c") java.lang.Integer bbx01c,
			@FormParam("bef07") java.lang.String bef07,
			@FormParam("bef08") java.lang.Integer bef08,
			@FormParam("bef09") java.math.BigDecimal bef09,
			@FormParam("bef10") java.lang.String bef10,
			@FormParam("bef11") java.math.BigDecimal bef11,
			@FormParam("bby01") java.lang.Integer bby01,
			@FormParam("bef13") java.lang.String bef13,
			@FormParam("bef14") java.lang.String bef14,
			@FormParam("bef15") java.lang.String bef15,
			@FormParam("bef16") java.lang.String bef16,
			@FormParam("bef17") java.lang.Integer bef17,
			@FormParam("bef18") java.lang.Integer bef18,
			@FormParam("bef19") java.lang.String bef19,
			@FormParam("bef20") java.lang.Byte bef20,
			@FormParam("bck01") java.lang.Integer bck01,
			@FormParam("bef22") java.lang.String bef22,
			@FormParam("bef23") java.lang.String bef23,
			@FormParam("bef24") java.math.BigDecimal bef24,
			@Context HttpServletResponse servletResponse
	) throws Exception {
		Bef1 bef1 = new Bef1();
		bef1.setBef01(bef01);
		bef1.setBbx01a(bbx01a);
		bef1.setRownr(rownr);
		bef1.setBbx01b(bbx01b);
		bef1.setBef05(bef05);
		bef1.setBbx01c(bbx01c);
		bef1.setBef07(bef07);
		bef1.setBef08(bef08);
		bef1.setBef09(bef09);
		bef1.setBef10(bef10);
		bef1.setBef11(bef11);
		bef1.setBby01(bby01);
		bef1.setBef13(bef13);
		bef1.setBef14(bef14);
		bef1.setBef15(bef15);
		bef1.setBef16(bef16);
		bef1.setBef17(bef17);
		bef1.setBef18(bef18);
		bef1.setBef19(bef19);
		bef1.setBef20(bef20);
		bef1.setBck01(bck01);
		bef1.setBef22(bef22);
		bef1.setBef23(bef23);
		bef1.setBef24(bef24);

		return bef1 = bef1Bo.save(bef1);

	}
	/**
     * 删除数据库中与传入的值对象对应的记录
     * @param vo 与数据库中记录对应的值对象
     * @return type : boolean 返回删除操作是否成功
     * @throws Exception
     */
	@DELETE
	@Path("{id}")
	public boolean removeBef1(@PathParam("id") String id) throws Exception{
		if(id == null) return false;
    	return bef1Bo.remove(id);

	}
	
}
